<template>
  <div class="swAuConductorShort">
    <basic-container>
      <avue-crud
        ref="crud"
        :option="option"
        :table-loading="listLoading"
        :data="list"
        :page.sync="page"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @refresh-change="getList"
        @on-load="getList">
        <template slot-scope="scope" slot="menuRight">
          <el-button type="primary"  size="mini" @click="exportData">导出</el-button>
        </template>
        <template slot-scope="scope" slot="lineCodeSearch">
          <el-select v-model="searchForm.lineCode" placeholder="请选择" style="width: 150px" @change="changeLine" clearable filterable>
            <el-option
              v-for="(item,index) in lineCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="stationCodeSearch">
          <el-select v-model="searchForm.stationCode" placeholder="请选择" style="width: 150px" clearable @change="changeStation" filterable>
            <el-option
              v-for="(item,index) in stationCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="tvmCodeSearch">
          <el-select v-model="searchForm.tvmCode" placeholder="请选择" style="width: 150px" filterable>
            <el-option
              v-for="(item,index) in tvmCodes"
              :key="index"
              :label="item.tvmCode"
              :value="item.tvmCode">
            </el-option>
          </el-select>
        </template>
        <template slot="search" slot-scope="{row,size}" >
          <el-form-item label="差异条件" style="width: 300px">
            <el-select v-model="searchForm.isDiffMoney" placeholder="请选择">
              <el-option label="不等于0" value="0"></el-option>
              <el-option label="等于0" value="1"></el-option>
              <!-- <el-option label="大于0" value="2"></el-option> -->
            </el-select>
          </el-form-item>
        </template>
        <template slot="searchMenu" slot-scope="{row,size}">
          <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm)}" icon="el-icon-delete">清空</el-button>
        </template>

        <!-- <template slot-scope="scope" slot="menu">
          <el-button type="text" size="small"
                     plain @click.stop="jiezhangdanju(scope.row)">结账单据</el-button>
          <el-button type="text" size="small"
                     v-if="scope.row.assistInvestStatus==3"
                     plain @click.stop="xiechaPreviwer(scope.row)">协查回馈预览</el-button>
        </template> -->

      </avue-crud>
<HuikuiInfo ref="xiechaDialog" v-if="xiechaDialog"></HuikuiInfo>
      <jiezhangdanju ref="jiezhangdanju"></jiezhangdanju>
    </basic-container>
  </div>
</template>

<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {mapGetters} from 'vuex';
  import HuikuiInfo from '@/views/subwayRat/TVMRevenueVarianceAudit/TvmChaYiDXC/TvmTicketCYXC/HuikuiInfo.vue';
  import jiezhangdanju from './../HuikuiInfo';
  import {
    getgetStationCodes, getLineAllAsyn,
    getLineCodes, getStationByCode,
    getSwPmTvmCodeList,
    setSearchFiledsEmpty
  } from "../../../../../api/subwayRat/commonCheck";
  import {exportDataToExcel} from "../../../../../api/subwayRat/exportSelf";
  import transitUtil from "../../../../../api/subwayRat/transitUtil";
  import {
    get_tvm_other_ZN_Option,
    get_cz_xw_SwAuTvmMoneyAssistList
  } from "../../../../../api/stationTiecketManager/xianWngCJXXQR/tvmPiaoKuanCY/otherYunYingZXDLCK";
  export default {
    components: {HuikuiInfo,jiezhangdanju},
    name: 'swAuConductorShort',
    data() {
      return {
        type : 0,
        userList:[],
        tvmCodes:[],
        xiechaDialog:false,//协查结果的弹框
        batchBuKuanDialog:false,
        lineCodes:[],
        stationCodes:[],
        selectKeys:[], //存放对像
        selectKeyVals:[], //存放值
        option: get_tvm_other_ZN_Option(),
        listLoading: true,
        listLoadingLimit: true,
        searchForm:{
          lineCode:'',
          stationCode:'',
          tvmOrder:'',
          isDiffMoney: '0'
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20, // 每页显示多少条,
          isAsc: false// 是否倒序
        },
        list : [],
        listLimit : []
      }
    },
    computed: {
    },
    watch: {
    },
    created() {
    },
    methods: {
      setSearchFiledsEmpty,
      batchBuKuan(){
        if(this.selectKeyVals.length<=0){
          this.$message.warning("请至少选择一条数据操作！");
          return;
        }
        for(let i=0;i<this.selectKeys.length;i++){
          if ( 1 == this.selectKeys[i].isSupPayment){
            this.$message.warning("勾选数据中存在已补款数据！");
            return
          }
        }
        this.batchBuKuanDialog=true;
        let rows=[];
        Object.assign(rows,this.selectKeys);
        this.$nextTick(()=>{
          this.$refs.batchBuKuan.dialogVisible=true;
          this.$refs.batchBuKuan.getList(rows,this);
        })

      },
      oneBuKuan(row){
        this.buKuanDialog=true;
        this.$nextTick(()=>{
          this.$refs.buKuan.dialogVisible=true;
          this.$refs.buKuan.recallShow(row,this);
        })
      },
      xiechaPreviwer(row){ //协查结果
        let th=this;
        this.xiechaDialog=true;
        this.$nextTick(res=>{
          th.$refs.xiechaDialog.remoteOpen(row); //打开协查结果
        })
      },
      jiezhangdanju(row){
        let th=this;
        this.$refs.jiezhangdanju.dialogVisible=true;
        this.$nextTick(res=>{
          th.$refs.jiezhangdanju.recallShow(row,this);
        })
      },
      async exportData(){ // 导出
        this.searchForm.pageNo=1;
        this.searchForm.pageSize=1000000000;
        if(this.selectKeys.length>0){
          let newData = JSON.parse(JSON.stringify(this.selectKeys));
          exportDataToExcel(newData,this.option.column,'TVM票款差异-其他运营中心查看');
        }else {
          let res=await get_cz_xw_SwAuTvmMoneyAssistList(this.searchForm);
          let data = res.data.data;
          exportDataToExcel(data,this.option.column,'TVM票款差异-其他运营中心查看');
        }
      },
      getList() {
        this.listLoading = true;
        Object.assign(this.searchForm,this.page);
        this.searchForm.userCode = this.$store.getters.userInfo.userCode;
        get_cz_xw_SwAuTvmMoneyAssistList(this.searchForm).then((response)=>{
          this.list = response.data.data;
          this.listLoading = false;
          this.page.total=response.data.total;
        });
      },
      handleFilter(params, done) {
        Object.assign(this.searchForm,params);
        this.getList()
        done()
      },
      selectionChange(list){
        this.selectKeys=list;
        this.selectKeyVals=[];
        for(let i=0;i<list.length;i++){
          this.selectKeyVals.push(list[i].id);
        }
      },
      changeLine(v){ //改变线路时
        let p={};
        p.line_code=v;
        getStationByCode(p).then(res=>{
          this.stationCodes=res.data;
          this.searchForm.stationCode='';
          this.searchForm.tvmOrder = '';
        })
      },
      changeStation(v){
        getSwPmTvmCodeList({lineCode:this.searchForm.lineCode,stationCode:v}).then(r=>{
          this.tvmCodes=r.data;
          this.searchForm.tvmOrder='';
        });
      }
    },
    mounted() {
      // getLineAllAsyn().then(res=>{ //获取线路
      //   this.lineCodes=res.data;
      // });
      getLineCodes().then(res=>{ //获取线路
          this.lineCodes=res;
      });

    }
  }
</script>
<style lang="scss">
</style>
